<html>

	<head>
		<title>优惠券管理</title>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">

		<link href="../../css/skin/default/style.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="../../css/dialog.css">
		<link href="../../js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />

		<script src="../../js/lib/jquery/jquery-1.10.2.min.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>

		<script src="../../js/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
		<script src="../../js/lib/jquery.form.js" type="text/javascript"></script>
		<script src="../../js/lib/json2.js" type="text/javascript"></script>
		<script src="../../js/dialog.js"></script>
		<script src="../../js/constants.js" type="text/javascript"></script>
		<script src="../../js/api.js" type="text/javascript"></script>
		<style>
			a:hover {
				cursor: pointer;
			}
		</style>
		<script type="text/javascript">
			var manager;
			$(document).hover(parent.hindMenu);
			var ctype = $api.getparastr("ctype");
			var couponUrl = BaseUrl + "Coupon?token=" + $api.getStorage("token") + "&ctype=" + ctype;

			$(function() {
				var url = couponUrl + "&key=";
				manager = $("#maingrid4").ligerGrid({
					columns: [{
							display: '摘要',
							name: 'Fsummary',
							width: 160,
							align: 'left'
						},
						{
							display: '限领数量(单账户)',
							name: 'Flimitnum',
							width: 160,
							render: function(rowdata, rowindex, value) {
								if(rowdata.Flimitnum == 0 || $api.isEmpty(rowdata.Flimitnum))
									return "不限次数！";
								return "每人限领" + rowdata.Flimitnum + "次";
							}
						},
						{
							display: '描述',
							name: 'Memo',
							minWidth: 300,
							align: 'left',
							render: function(rowdata, rowindex, value) {
								var ret = '';
								if(!$api.isEmpty(rowdata.Fstocknum)) {
									ret = "目标库存:" + rowdata.Fstocknum;
									if(!$api.isEmpty(rowdata.Fcurrnum))
										ret += ";领取数:" + rowdata.Fcurrnum;
									if(!$api.isEmpty(rowdata.Fusenum))
										ret += ";使用数:" + rowdata.Fusenum; 
								}
								if(rowdata.Fctype == 1 ){
									if(rowdata.Fsdtype == 1) {
									var index = rowdata.Fsdate.indexOf("T");
									rowdata.Fsdate = rowdata.Fsdate.substr(0,index);
									index = rowdata.Fedate.indexOf("T");
									rowdata.Fedate = rowdata.Fedate.substr(0,index);
									var iday = $api.TimeDiff(rowdata.Fedate);
									ret += "消费满￥" + $api.toMoney(rowdata.Ffullvalue) + "时使用,减￥" + $api.toMoney(rowdata.Ffacevalue) + "<br/>" ;
									
									if(iday < 0)
										ret +="<span style='color:#CA1712'>已过期</span>";
									else
										ret +="活动周期:" + rowdata.Fsdate + "至" + rowdata.Fedate;
								}
								if(rowdata.Fsdtype == 2) {
									ret += "消费满￥" + $api.toMoney(rowdata.Ffullvalue) + "时使用,减￥" + $api.toMoney(rowdata.Ffacevalue) + "<br/>" +
										"活动周期:领取后" + rowdata.Fday + "天使用有效";
								}
								}
								else{
									ret += "购买价值￥" + $api.toMoney(rowdata.Ffullvalue)+";可用￥"+ $api.toMoney(rowdata.Ffacevalue) ;
								}
								return ret;
							}
						},
						{
							display: '创建时间',
							name: 'Fdate',
							width: 200,
							type: 'date',
							render: function(rowdata, rowindex, value) {
								var data = rowdata.Fdate.replace("T", " ");
								var index = data.indexOf(".");
								return data.substr(0, index);
							}
						}
					],
					dataAction: 'local',
					url: url,
					width: '100%',
					height: '85%',
					checkbox:true,
					pageSize: 50,
					rowHeight: '80',
					rownumbers: true,
					method: 'get',
					isScroll: true,
					usePager: true
				});
			});

			function f_save() {

				var rows = manager.getSelectedRows();
				if(rows) {
					return rows;
				}
				return null;
			}

			function doserch() {
				var key = $("#txtKeywords").val();

				var url = couponUrl + '&key=' + key + "&ctype=" + ctype;
				manager.GetDataByURL(url);

			}
		</script>

	</head>

	<body class="mainbody">
		<form id="form1" onsubmit="return false">
			<div class="toolbar-wrap">
				<div  class="toolbar">

					<div class="r-list">
						<input type=text ID="txtKeywords" placeholder="名称" class="keyword" />
						<a class='btn-search' href='#' onclick='doserch();'></a>
					</div>
				</div>
			</div>
			<div id="maingrid4" style="margin: 0px;background:#fff;"></div>

		</form>

	</body>

</html>